package com.ntlg.sendmessage.controller;

import com.alibaba.druid.sql.visitor.functions.If;
import com.aliyuncs.utils.StringUtils;
import com.ntlg.sendmessage.pojo.Phone;
import com.ntlg.sendmessage.service.SendSmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class SendSmsController {
    @Autowired
    SendSmsService sendSmsService;

    @RequestMapping("/Sms")
    @ResponseBody
   public String SendSms(@RequestParam("PhoneNumber") String PhoneNumber){
        /*从数据库中查询号码，AccesssKey账户，AccessKey密码*/
        /*此处可以取出多种模板*/
        Phone phone = sendSmsService.selectPhone(PhoneNumber);
     if (phone==null){
        return "该手机号未注册！";
     }
        /*调用发送短信的接口*/
        String message = sendSmsService.SendSms(phone.getPhoneNumbers(), phone.getSignName(), phone.getTemplateCode());
        return message;
    }
}
